@ECHO OFF

SETLOCAL EnableDelayedExpansion

SET prefix=[Package]
SET OutputDirectory=dist
SET ZipBinDirectory=etc\bin\win\7z

ECHO %prefix% Start packaging ZenS Console

IF EXIST "%OutputDirectory%" (
	RMDIR /S /Q %OutputDirectory%
)

CALL play dist

SET PackageFileName=""
FOR %%f IN (%OutputDirectory%\*.zip) DO (
	SET PackageFileName=%%~nxf
	GOTO EOFL
)
:EOFL

IF NOT "%PackageFileName%" == "" (
	ECHO File: %PackageFileName%
	%ZipBinDirectory%\7za.exe x -o%OutputDirectory% -y %OutputDirectory%\%PackageFileName% > nul
	DEL /F /Q %OutputDirectory%\%PackageFileName%
)

SET PackageDirName=""	
FOR /D %%d IN (%OutputDirectory%\*) DO (
	SET PackageDirName=%%~nxd
	GOTO EODL
)
:EODL

IF NOT "%PackageDirName%" == "" (
		ECHO Directory: %PackageDirName%
		MOVE /Y %OutputDirectory%\%PackageDirName% %OutputDirectory%\console
		XCOPY conf\* %OutputDirectory%\console\conf\ /S /E /Y
		XCOPY resources\* %OutputDirectory%\console\resources\ /S /E /Y
		CD dist
		..\%ZipBinDirectory%\7za.exe a -tzip -y %PackageFileName% * > nul
		RMDIR /S /Q console
		CD ..
	)

:END

ECHO %prefix% Finished package in available at %OutputDirectory%\%PackageFilename%
